home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / hplip / ui / scrollprintsettings.py < prev    next >
Text File  |  2008-10-13  |  38KB  |  992 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. # Local
  23. from base.g import *
  24. from base import utils
  25. from prnt import cups
  26. from jobstoragemixin import JobStorageMixin
  27.  
  28. # Qt
  29. from qt import *
  30. from scrollview import ScrollView
  31.  
  32. # Std Lib
  33. import os.path
  34. import os
  35.  
  36.  
  37. class OptionComboBox(QComboBox):
  38.     def __init__(self, rw, parent, name, group, option, choices, default, typ=cups.PPD_UI_PICKONE, other=None):
  39.         QComboBox.__init__(self, rw, parent, name)
  40.         self.group = group
  41.         self.option = option
  42.         self.choices = choices
  43.         self.default = default
  44.         self.typ = typ
  45.         self.other = other
  46.  
  47.     def setDefaultPushbutton(self, pushbutton):
  48.         self.pushbutton = pushbutton
  49.         
  50.     def setOther(self, other):
  51.         self.other = other
  52.  
  53.  
  54. class OptionSpinBox(QSpinBox):
  55.     def __init__(self,  parent, name, group, option, default):
  56.         QSpinBox.__init__(self, parent, name)
  57.         self.group = group
  58.         self.option = option
  59.         self.default = default
  60.  
  61.     def setDefaultPushbutton(self, pushbutton):
  62.         self.pushbutton = pushbutton
  63.  
  64.  
  65. class OptionButtonGroup(QButtonGroup):
  66.     def __init__(self,  parent, name, group, option, default):
  67.         QButtonGroup.__init__(self, parent, name)
  68.         self.group = group
  69.         self.option = option
  70.         self.default = default
  71.  
  72.     def setDefaultPushbutton(self, pushbutton):
  73.         self.pushbutton = pushbutton
  74.             
  75.         
  76. class DefaultPushButton(QPushButton):
  77.     def __init__(self,  parent, name, group, option, choices, default, control, typ):
  78.         QPushButton.__init__(self, parent, name)
  79.         self.group = group
  80.         self.option = option
  81.         self.default = default
  82.         self.control = control
  83.         self.typ = typ
  84.         self.choices = choices
  85.         
  86.  
  87.  
  88. class ScrollPrintSettingsView(ScrollView):
  89.     utils.mixin(JobStorageMixin)
  90.  
  91.     def __init__(self, service, parent=None, name=None, fl=0):
  92.         ScrollView.__init__(self, service, parent, name, fl)
  93.         
  94.         self.initJobStorage(True)
  95.  
  96.     
  97.     
  98.     def fillControls(self):
  99.         QApplication.setOverrideCursor(QApplication.waitCursor)
  100.     
  101.         ScrollView.fillControls(self)
  102.     
  103.         self.loading = True
  104.         cups.resetOptions()
  105.         cups.openPPD(self.cur_printer)
  106.  
  107.         #if 1:
  108.         try:
  109.             if 1:
  110.             #try:
  111.                 current_options = dict(cups.getOptions())
  112.                 
  113.                 if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  114.                     self.addGroupHeading("basic", self.__tr("Basic"))
  115.                     log.debug("Group: Basic")
  116.     
  117.                     # Basic
  118.                         # PageSize (in PPD section)
  119.                         # orientation-requested
  120.                         # sides
  121.                         # outputorder
  122.                         # Collate
  123.     
  124.                     
  125.                     current = current_options.get('orientation-requested', '3')
  126.     
  127.                     self.addItem("basic", "orientation-requested", self.__tr("Page Orientation"), 
  128.                         cups.PPD_UI_PICKONE, current, 
  129.                         [('3', self.__tr('Portrait')), 
  130.                          ('4', self.__tr('Landscape')), 
  131.                          ('5', self.__tr('Reverse landscape')), 
  132.                          ('6', self.__tr('Reverse portrait'))], '3')
  133.     
  134.                     log.debug("Option: orientation-requested")
  135.                     log.debug("Current value: %s" % current)
  136.     
  137.                     duplexer = self.cur_device.dq.get('duplexer', 0)
  138.                     log.debug("Duplexer = %d" % duplexer)
  139.     
  140.                     if duplexer:
  141.                         current = current_options.get('sides', 'one-sided')
  142.                         self.addItem("basic", "sides", 
  143.                             self.__tr("Duplex (Print on both sides of the page)"), 
  144.                             cups.PPD_UI_PICKONE, current, 
  145.                             [('one-sided',self.__tr('Single sided')), 
  146.                              ('two-sided-long-edge', self.__tr('Two sided (long edge)')), 
  147.                              ('two-sided-short-edge', self.__tr('Two sided (short edge)'))], 'one-sided')
  148.     
  149.                         log.debug("Option: sides")
  150.                         log.debug("Current value: %s" % current)
  151.     
  152.                     current = current_options.get('outputorder', 'normal')
  153.     
  154.                     self.addItem("basic", "outputorder", 
  155.                         self.__tr("Output Order (Print last page first)"), 
  156.                         cups.PPD_UI_PICKONE, current, 
  157.                         [('normal', self.__tr('Normal (Print first page first)')), 
  158.                          ('reverse', self.__tr('Reversed (Print last page first)'))], 'normal')
  159.     
  160.                     log.debug("Option: outputorder")
  161.                     log.debug("Current value: %s" % current)
  162.     
  163.                     current = int(utils.to_bool(current_options.get('Collate', '0')))
  164.     
  165.                     self.addItem("basic", "Collate", 
  166.                         self.__tr("Collate (Group together multiple copies)"), 
  167.                         cups.PPD_UI_BOOLEAN, current, 
  168.                         [], 0)
  169.     
  170.                     log.debug("Option: Collate")
  171.                     log.debug("Current value: %s" % current)
  172.  
  173.                 groups = cups.getGroupList()
  174.  
  175.                 for g in groups:
  176.                     log.debug("Group: %s" % repr(g))
  177.                     
  178.                     if 'jobretention' in g.lower():
  179.                         log.debug("HPJobRetention skipped.")
  180.                         continue                    
  181.                     
  182.                     text, num_subgroups = cups.getGroup(g) 
  183.                     read_only = 'install' in g.lower()
  184.                     
  185.                     try:
  186.                         text = text.decode('utf-8')
  187.                     except UnicodeDecodeError:
  188.                         pass
  189.                     
  190.                     if g.lower() == 'printoutmode':
  191.                         text = self.__tr("Quality")
  192.                     
  193.                     self.addGroupHeading(g, text, read_only)
  194.  
  195.                     log.debug("  Text: %s" % repr(text))
  196.                     log.debug("Num subgroups: %d" % num_subgroups)
  197.  
  198.                     options = cups.getOptionList(g)
  199.  
  200.                     for o in options:
  201.                         log.debug("  Option: %s" % repr(o))
  202.  
  203.                         if 'pageregion' in o.lower():
  204.                             log.debug("Page Region skipped.")
  205.                             continue
  206.                             
  207.                         
  208.  
  209.                         option_text, defchoice, conflicted, ui  = cups.getOption(g, o)
  210.  
  211.                         try:
  212.                             option_text = option_text.decode('utf-8')
  213.                         except UnicodeDecodeError:
  214.                             pass
  215.                         
  216.                         if o.lower() == 'quality':
  217.                             option_text = self.__tr("Quality")
  218.                                                     
  219.                         log.debug("    Text: %s" % repr(option_text))
  220.                         log.debug("    Defchoice: %s" % repr(defchoice))
  221.  
  222.                         choices = cups.getChoiceList(g, o)
  223.  
  224.                         value = None
  225.                         choice_data = []
  226.                         for c in choices:
  227.                             log.debug("    Choice: %s" % repr(c))
  228.  
  229.                             # TODO: Add custom paper size controls
  230.                             if 'pagesize' in o.lower() and 'custom' in c.lower():
  231.                                 log.debug("Skipped.")
  232.                                 continue
  233.  
  234.                             choice_text, marked = cups.getChoice(g, o, c)
  235.  
  236.                             try:
  237.                                 choice_text = choice_text.decode('utf-8')
  238.                             except UnicodeDecodeError:
  239.                                 pass
  240.                             
  241.                             log.debug("      Text: %s" % repr(choice_text))
  242.  
  243.                             if marked:
  244.                                 value = c
  245.  
  246.                             choice_data.append((c, choice_text))
  247.  
  248.  
  249.                         self.addItem(g, o, option_text, ui, value, choice_data, defchoice, read_only)
  250.                         
  251. ##                        if 'pagesize' in o.lower(): # and 'custom' in c.lower():
  252. ##                            current = 0.0
  253. ##                            width_widget = self.addItem("custom", "custom-width", self.__tr("Custom Paper Width"), cups.UI_UNITS_SPINNER,
  254. ##                                current, (0.0, 0.0), 0.0) 
  255. ##                            
  256. ##                            current = 0.0
  257. ##                            height_widget = self.addItem("custom", "custom-height", self.__tr("Custom Paper Height"), cups.UI_UNITS_SPINNER,
  258. ##                                current, (0.0, 0.0), 0.0) 
  259. ##                                
  260. ##                            if value.lower() == 'custom':
  261. ##                                pass
  262.  
  263.                 # N-Up
  264.                     # number-up
  265.                     # number-up-layout
  266.                     # page-border
  267.  
  268.                 self.addGroupHeading("nup", 
  269.                     self.__tr("N-Up (Multiple document pages per printed page)"))
  270.  
  271.                 log.debug("Group: N-Up")
  272.  
  273.                 current = current_options.get('number-up', '1')
  274.  
  275.                 self.addItem("nup", "number-up", self.__tr("Pages per Sheet"), 
  276.                     cups.PPD_UI_PICKONE, current, 
  277.                     [('1', self.__tr('1 sheet per page')), 
  278.                      ('2', self.__tr('2 sheets per page')), 
  279.                      ('4', self.__tr('4 sheets per page'))], '1')
  280.  
  281.                 log.debug("  Option: number-up")
  282.                 log.debug("  Current value: %s" % current)
  283.  
  284.                 current = current_options.get('number-up-layout', 'lrtb')
  285.  
  286.                 self.addItem("nup", "number-up-layout", self.__tr("Layout"), 
  287.                     cups.PPD_UI_PICKONE, current, 
  288.                     [('btlr', self.__tr('Bottom to top, left to right')), 
  289.                      ('btrl', self.__tr('Bottom to top, right to left')), 
  290.                      ('lrbt', self.__tr('Left to right, bottom to top')), 
  291.                      ('lrtb', self.__tr('Left to right, top to bottom')),
  292.                      ('rlbt', self.__tr('Right to left, bottom to top')), 
  293.                      ('rltb', self.__tr('Right to left, top to bottom')),
  294.                      ('tblr', self.__tr('Top to bottom, left to right')), 
  295.                      ('tbrl', self.__tr('Top to bottom, right to left')) ], 'lrtb')
  296.  
  297.                 log.debug("  Option: number-up-layout")
  298.                 log.debug("  Current value: %s" % current)
  299.  
  300.                 current = current_options.get('page-border', 'none')
  301.  
  302.                 self.addItem("nup", "page-border", 
  303.                     self.__tr("Printed Border Around Each Page"), 
  304.                     cups.PPD_UI_PICKONE, current,
  305.                     [('double', self.__tr("Two thin borders")), 
  306.                      ("double-thick", self.__tr("Two thick borders")),
  307.                      ("none", self.__tr("No border")), 
  308.                      ("single", self.__tr("One thin border")), 
  309.                      ("single-thick", self.__tr("One thick border"))], 'none')
  310.  
  311.                 log.debug("  Option: page-border")
  312.                 log.debug("  Current value: %s" % current)
  313.  
  314.                 # Adjustment
  315.                     # brightness
  316.                     # gamma
  317.  
  318.                 if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  319.                     self.addGroupHeading("adjustment", self.__tr("Printout Appearance"))
  320.     
  321.                     current = int(current_options.get('brightness', 100))
  322.     
  323.                     log.debug("  Option: brightness")
  324.                     log.debug("  Current value: %s" % current)
  325.     
  326.                     self.addItem("adjustment", "brightness", self.__tr("Brightness"),
  327.                         cups.UI_SPINNER, current, (0, 200), 100, suffix=" %")
  328.     
  329.                     current = int(current_options.get('gamma', 1000))
  330.     
  331.                     log.debug("  Option: gamma")
  332.                     log.debug("  Current value: %s" % current)
  333.     
  334.                     self.addItem("adjustment", "gamma", self.__tr("Gamma"), cups.UI_SPINNER, current,
  335.                         (1, 10000), 1000)
  336.     
  337.                 # Margins (pts)
  338.                     # page-left
  339.                     # page-right
  340.                     # page-top
  341.                     # page-bottom
  342.  
  343. ##                if 0:
  344. ##                    # TODO: cupsPPDPageSize() fails on LaserJets. How do we get margins in this case? Defaults?
  345. ##                    # PPD file for LJs has a HWMargin entry...
  346. ##                    page, page_width, page_len, left, bottom, right, top = cups.getPPDPageSize()
  347. ##
  348. ##                    right = page_width - right
  349. ##                    top = page_len - top
  350. ##
  351. ##                    self.addGroupHeading("margins", self.__tr("Margins"))
  352. ##                    current_top = current_options.get('page-top', 0) # pts
  353. ##                    current_bottom = current_options.get('page-bottom', 0) # pts
  354. ##                    current_left = current_options.get('page-left', 0) # pts
  355. ##                    current_right = current_options.get('page-right', 0) # pts
  356. ##
  357. ##                    log.debug("  Option: page-top")
  358. ##                    log.debug("  Current value: %s" % current_top)
  359. ##
  360. ##                    self.addItem("margins", "page-top", self.__tr("Top margin"), 
  361. ##                        cups.UI_UNITS_SPINNER, current_top,
  362. ##                        (0, page_len), top)
  363. ##
  364. ##                    self.addItem("margins", "page-bottom", self.__tr("Bottom margin"), 
  365. ##                        cups.UI_UNITS_SPINNER, current_bottom,
  366. ##                        (0, page_len), bottom)
  367. ##
  368. ##                    self.addItem("margins", "page-left", self.__tr("Right margin"), 
  369. ##                        cups.UI_UNITS_SPINNER, current_left,
  370. ##                        (0, page_width), left)
  371. ##
  372. ##                    self.addItem("margins", "page-right", self.__tr("Left margin"), 
  373. ##                        cups.UI_UNITS_SPINNER, current_right,
  374. ##                        (0, page_width), right)
  375.  
  376.                 # Image Printing
  377.                     # position
  378.                     # natural-scaling
  379.                     # saturation
  380.                     # hue
  381.  
  382.                 self.addGroupHeading("image", self.__tr("Image Printing"))
  383.  
  384.                 current = current_options.get('fitplot', 'false')
  385.                 
  386.                 self.addItem("image", "fitplot", 
  387.                     self.__tr("Fit to Page"), 
  388.                     cups.PPD_UI_BOOLEAN, current, 
  389.                     [], 0)
  390.  
  391.                 
  392.                 current = current_options.get('position', 'center')
  393.  
  394.                 self.addItem("image", "position", self.__tr("Position on Page"), 
  395.                     cups.PPD_UI_PICKONE, current, 
  396.                     [('center', self.__tr('Centered')), 
  397.                      ('top', self.__tr('Top')), 
  398.                      ('left', self.__tr('Left')), 
  399.                      ('right', self.__tr('Right')), 
  400.                      ('top-left', self.__tr('Top left')), 
  401.                      ('top-right', self.__tr('Top right')), 
  402.                      ('bottom', self.__tr('Bottom')),
  403.                      ('bottom-left', self.__tr('Bottom left')), 
  404.                      ('bottom-right', self.__tr('Bottom right'))], 'center')
  405.  
  406.                 log.debug("  Option: position")
  407.                 log.debug("  Current value: %s" % current)
  408.  
  409.                 if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  410.                     current = int(current_options.get('saturation', 100))
  411.     
  412.                     log.debug("  Option: saturation")
  413.                     log.debug("  Current value: %s" % current)
  414.     
  415.                     self.addItem("image", "saturation", self.__tr("Saturation"), 
  416.                         cups.UI_SPINNER, current, (0, 200), 100, suffix=" %")
  417.     
  418.                     current = int(current_options.get('hue', 0))
  419.     
  420.                     log.debug("  Option: hue")
  421.                     log.debug("  Current value: %s" % current)
  422.     
  423.                     self.addItem("image", "hue", self.__tr("Hue (color shift/rotation)"), 
  424.                         cups.UI_SPINNER, current,
  425.                         (-100, 100), 0)
  426.  
  427.                 current = int(current_options.get('natural-scaling', 100))
  428.  
  429.                 log.debug("  Option: natural-scaling")
  430.                 log.debug("  Current value: %s" % current)
  431.  
  432.                 self.addItem("image", "natural-scaling", 
  433.                     self.__tr('"Natural" Scaling (relative to image)'), 
  434.                     cups.UI_SPINNER, current, (1, 800), 100, suffix=" %")
  435.  
  436.                 current = int(current_options.get('scaling', 100))
  437.  
  438.                 log.debug("  Option: scaling")
  439.                 log.debug("  Current value: %s" % current)
  440.  
  441.                 self.addItem("image", "scaling", self.__tr("Scaling (relative to page)"), 
  442.                     cups.UI_SPINNER, current,
  443.                     (1, 800), 100, suffix=" %")
  444.  
  445.                 # Misc
  446.                     # PrettyPrint
  447.                     # job-sheets
  448.                     # mirror
  449.  
  450.                 self.addGroupHeading("misc", self.__tr("Miscellaneous"))
  451.  
  452.                 log.debug("Group: Misc")
  453.  
  454.                 current = int(utils.to_bool(current_options.get('prettyprint', '0')))
  455.  
  456.                 self.addItem("misc", "prettyprint", 
  457.                     self.__tr('"Pretty Print" Text Documents (Add headers and formatting)'),
  458.                     cups.PPD_UI_BOOLEAN, current, [], 0)
  459.  
  460.                 log.debug("  Option: prettyprint")
  461.                 log.debug("  Current value: %s" % current)
  462.  
  463.                 if not self.cur_device.device_type == DEVICE_TYPE_FAX:
  464.                     current = current_options.get('job-sheets', 'none').split(',')
  465.                     
  466.                     try:
  467.                         start = current[0]
  468.                     except IndexError:
  469.                         start = 'none'
  470.                         
  471.                     try:
  472.                         end = current[1]
  473.                     except IndexError:
  474.                         end = 'none'
  475.                     
  476.                     # TODO: Look for locally installed banner pages beyond the default CUPS ones?
  477.                     self.addItem("misc", "job-sheets", self.__tr("Banner Pages"), cups.UI_BANNER_JOB_SHEETS, 
  478.                         (start, end), 
  479.                         [("none", self.__tr("No banner page")), 
  480.                          ('classified', self.__tr("Classified")), 
  481.                          ('confidential', self.__tr("Confidential")),
  482.                          ('secret', self.__tr("Secret")), 
  483.                          ('standard', self.__tr("Standard")), 
  484.                          ('topsecret', self.__tr("Top secret")), 
  485.                          ('unclassified', self.__tr("Unclassified"))], ('none', 'none'))
  486.                     
  487.                     log.debug("  Option: job-sheets")
  488.                     log.debug("  Current value: %s,%s" % (start, end))
  489.  
  490.                 current = int(utils.to_bool(current_options.get('mirror', '0')))
  491.  
  492.                 self.addItem("misc", "mirror", self.__tr('Mirror Printing'),
  493.                     cups.PPD_UI_BOOLEAN, current, [], 0)
  494.  
  495.                 log.debug("  Option: mirror")
  496.                 log.debug("  Current value: %s" % current)
  497.                 
  498.                 self.job_storage_avail = self.cur_device.mq['job-storage'] == JOB_STORAGE_ENABLE
  499.             
  500.                 #print current_options
  501.                 
  502.                 if self.job_storage_avail:
  503.                     self.addGroupHeading("jobstorage", self.__tr("Job Storage and Secure Printing"))
  504.                     self.addJobStorage(current_options)
  505.                     
  506.  
  507.             #except Exception, e:
  508.                 #log.exception()
  509.             #    pass
  510.  
  511.         finally:
  512.             cups.closePPD()
  513.             self.loading = False
  514.             QApplication.restoreOverrideCursor()
  515.             
  516.  
  517.     def optionComboBox_activated(self, a):
  518.         a = unicode(a)
  519.         sender = self.sender()
  520.         choice = None
  521.         
  522.         if sender.typ == cups.UI_BANNER_JOB_SHEETS:
  523.             start, end = None, None
  524.             for c, t in sender.choices:
  525.                 if t == a:
  526.                     start = c
  527.                     break
  528.                     
  529.             for c, t in sender.other.choices:
  530.                 if t == sender.other.currentText():
  531.                     end = c
  532.                     break
  533.                 
  534.             if sender.option == 'end':
  535.                 start, end = end, start
  536.  
  537.             if start is not None and \
  538.                 end is not None and \
  539.                 start.lower() == sender.default[0].lower() and \
  540.                 end.lower() == sender.default[1].lower():
  541.                     self.removePrinterOption('job-sheets')
  542.                     sender.pushbutton.setEnabled(False)
  543.             else:
  544.                 sender.pushbutton.setEnabled(True)
  545.                 
  546.                 if start is not None and \
  547.                     end is not None:
  548.                     
  549.                     self.setPrinterOption('job-sheets', ','.join([start, end]))
  550.                 
  551.         else:
  552.             choice = None
  553.             for c, t in sender.choices:
  554.                 if t == a:
  555.                     choice = c
  556.                     break
  557.     
  558.             if choice is not None and choice.lower() == sender.default.lower():
  559.                 self.removePrinterOption(sender.option)
  560.                 sender.pushbutton.setEnabled(False)
  561.             else:
  562.                 sender.pushbutton.setEnabled(True)
  563.     
  564.                 if choice is not None:
  565.                     self.setPrinterOption(sender.option, choice)
  566.                     
  567.             self.linkPrintoutModeAndQuality(sender.option, choice)
  568.  
  569.     
  570.     def linkPrintoutModeAndQuality(self, option, choice):
  571.         if option.lower() == 'quality' and \
  572.             choice is not None:
  573.             
  574.             try:
  575.                 c = self.items['o:PrintoutMode'].control
  576.             except KeyError:
  577.                 return
  578.             else:
  579.                 if c is not None:
  580.                     if choice.lower() == 'fromprintoutmode':
  581.                         # from printoutmode selected
  582.                         # determine printoutmode option combo enable state
  583.                         c.setEnabled(True)
  584.                         QToolTip.remove(c)
  585.                         a = unicode(c.currentText())
  586.                         
  587.                         # determine printoutmode default button state
  588.                         link_choice = None
  589.                         for x, t in c.choices:
  590.                             if t == a:
  591.                                 link_choice = x
  592.                                 break
  593.                 
  594.                         if link_choice is not None and \
  595.                             link_choice.lower() == c.default.lower():
  596.                             
  597.                             c.pushbutton.setEnabled(False)
  598.                         else:
  599.                             c.pushbutton.setEnabled(True)
  600.                     
  601.                     else: # fromprintoutmode not selected, disable printoutmode
  602.                         c.setEnabled(False)
  603.                         QToolTip.add(c, self.__tr("""Set Quality to "Controlled by 'Printout Mode'" to enable."""))
  604.                         c.pushbutton.setEnabled(False)
  605.                             
  606.  
  607.  
  608.     def optionSpinBox_valueChanged(self, i):
  609.         sender = self.sender()
  610.  
  611.         if i == sender.default:
  612.             self.removePrinterOption(sender.option)
  613.             sender.pushbutton.setEnabled(False)
  614.         else:
  615.             sender.pushbutton.setEnabled(True)
  616.             self.setPrinterOption(sender.option, str(i))
  617.  
  618.             
  619.     def optionButtonGroup_clicked(self, b):
  620.         sender = self.sender()
  621.         b = int(b)
  622.  
  623.         if b == sender.default:
  624.             self.removePrinterOption(sender.option)
  625.             sender.pushbutton.setEnabled(False)
  626.         else:
  627.             sender.pushbutton.setEnabled(True)
  628.  
  629.             if b:
  630.                 self.setPrinterOption(sender.option, "true")
  631.             else:
  632.                 self.setPrinterOption(sender.option, "false")
  633.         
  634.  
  635.  
  636.     def defaultPushButton_clicked(self):
  637.         sender = self.sender()
  638.         sender.setEnabled(False)
  639.  
  640.         if sender.typ == cups.PPD_UI_BOOLEAN:
  641.             if sender.default:
  642.                 sender.control.setButton(1)
  643.             else:
  644.                 sender.control.setButton(0)
  645.                 
  646.             self.removePrinterOption(sender.option)
  647.  
  648.         elif sender.typ == cups.PPD_UI_PICKONE:
  649.             choice, text = None, None
  650.  
  651.             for c, t in sender.choices:
  652.                 if c == sender.default:
  653.                     choice = c
  654.                     text = t
  655.                     break
  656.  
  657.             if choice is not None:
  658.                 self.removePrinterOption(sender.option)
  659.                 sender.control.setCurrentText(text)
  660.                 
  661.                 self.linkPrintoutModeAndQuality(sender.option, choice)
  662.  
  663.         elif sender.typ == cups.UI_SPINNER:
  664.             sender.control.setValue(sender.default)
  665.             self.removePrinterOption(sender.option)
  666.             
  667.         elif sender.typ == cups.UI_BANNER_JOB_SHEETS:
  668.             start, end, start_text, end_text = None, None, None, None
  669.             for c, t in sender.choices:
  670.                 if c == sender.default[0]:
  671.                     start = c
  672.                     start_text = t
  673.                 
  674.                 if c == sender.default[1]:
  675.                     end = c
  676.                     end_text = t
  677.                     
  678.             if start is not None:
  679.                 sender.control[0].setCurrentText(start_text)
  680.                 
  681.             if end is not None:
  682.                 sender.control[1].setCurrentText(end_text)
  683.                 
  684.             self.removePrinterOption('job-sheets')
  685.                 
  686.  
  687.     def setPrinterOption(self, option, value):
  688.         cups.openPPD(self.cur_printer)
  689.  
  690.         try:
  691.             cups.addOption("%s=%s" % (option, value))
  692.             cups.setOptions()
  693.         finally:
  694.             cups.closePPD()
  695.  
  696.     def removePrinterOption(self, option):
  697.         cups.openPPD(self.cur_printer)
  698.  
  699.         try:
  700.             cups.removeOption(option)
  701.             cups.setOptions()
  702.         finally:
  703.             cups.closePPD()
  704.  
  705.  
  706.     def addItem(self, group, option, text, typ, value, choices, default, read_only=False, suffix=""):
  707.         widget, control = None, None
  708.  
  709.         if typ == cups.PPD_UI_BOOLEAN: # () On (*) Off widget
  710.             widget = self.getWidget()
  711.             layout = QGridLayout(widget, 1, 1, 5, 10, "layout")
  712.             default = int(utils.to_bool(str(default)))
  713.             value = int(utils.to_bool(str(value)))
  714.     
  715.             textLabel1 = QLabel(widget, "textLabel1")
  716.             layout.addWidget(textLabel1, 0, 0)
  717.     
  718.             buttonGroup = OptionButtonGroup(widget, "buttonGroup", group, option, default)
  719.             buttonGroup.setLineWidth(0)
  720.             buttonGroup.setColumnLayout(0,Qt.Vertical)
  721.             buttonGroup.layout().setSpacing(1)
  722.             buttonGroup.layout().setMargin(5)
  723.             buttonGroupLayout = QHBoxLayout(buttonGroup.layout())
  724.             buttonGroupLayout.setAlignment(Qt.AlignTop)
  725.     
  726.             defaultPushButton = DefaultPushButton(widget,"defaultPushButton", group, option, 
  727.                 choices, default, buttonGroup, typ)    
  728.     
  729.             buttonGroup.setDefaultPushbutton(defaultPushButton)
  730.             
  731.             layout.addWidget(defaultPushButton, 0, 3)
  732.             
  733.             spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  734.             layout.addItem(spacer1, 0, 1)
  735.             
  736.             onRadioButton = QRadioButton(buttonGroup,"onRadioButton")
  737.             buttonGroup.insert(onRadioButton, 1)
  738.             buttonGroupLayout.addWidget(onRadioButton)
  739.     
  740.             offRadioButton = QRadioButton(buttonGroup,"offRadioButton")
  741.             buttonGroup.insert(offRadioButton, 0)
  742.             buttonGroupLayout.addWidget(offRadioButton)
  743.     
  744.             layout.addWidget(buttonGroup, 0, 2)
  745.             
  746.             textLabel1.setText(text)
  747.             onRadioButton.setText(self.__tr("On"))
  748.             offRadioButton.setText(self.__tr("Off"))
  749.             
  750.             if value == default:
  751.                 defaultPushButton.setEnabled(False)
  752.                 
  753.             self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked)
  754.             self.connect(buttonGroup, SIGNAL("clicked(int)"), self.optionButtonGroup_clicked)
  755.  
  756.             x = self.__tr('Off')
  757.             if default:
  758.                 x = self.__tr('On')
  759.  
  760.             if value:
  761.                 buttonGroup.setButton(1)
  762.             else:
  763.                 buttonGroup.setButton(0)
  764.             
  765.             if read_only:
  766.                 onRadioButton.setEnabled(False)
  767.                 offRadioButton.setEnabled(False)
  768.                 defaultPushButton.setEnabled(False)
  769.             else:
  770.                 QToolTip.add(defaultPushButton, self.__tr('Set to default value of "%1".').arg(x))
  771.             
  772.             defaultPushButton.setText("Default")
  773.  
  774.         elif typ == cups.PPD_UI_PICKONE: # Combo box widget
  775.             widget = self.getWidget()
  776.  
  777.             layout1 = QHBoxLayout(widget,5,10,"layout1")
  778.  
  779.             textLabel1 = QLabel(widget,"textLabel1")
  780.             layout1.addWidget(textLabel1)
  781.  
  782.             spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  783.             layout1.addItem(spacer1)
  784.  
  785.             optionComboBox = OptionComboBox(0, widget, "optionComboBox", group, option, choices, default)
  786.             layout1.addWidget(optionComboBox)
  787.  
  788.             defaultPushButton = DefaultPushButton(widget,"defaultPushButton", group, option, 
  789.                 choices, default, optionComboBox, typ)
  790.  
  791.             optionComboBox.setDefaultPushbutton(defaultPushButton)
  792.  
  793.             layout1.addWidget(defaultPushButton)
  794.  
  795.             textLabel1.setText(text)
  796.             defaultPushButton.setText("Default")
  797.  
  798.             x, y = None, None
  799.             for c, t in choices:
  800.                 d = c.lower()
  801.                 if value is not None and d == value.lower():
  802.                     x = t
  803.  
  804.                 if d == default.lower():
  805.                     y = t
  806.  
  807.                 optionComboBox.insertItem(t)
  808.  
  809.             if x is not None:
  810.                 optionComboBox.setCurrentText(x)
  811.  
  812.             if value is not None and value.lower() == default.lower():
  813.                 defaultPushButton.setEnabled(False)
  814.                 
  815.             self.linkPrintoutModeAndQuality(option, value)
  816.  
  817.             if read_only:
  818.                 optionComboBox.setEnabled(False)
  819.                 defaultPushButton.setEnabled(False)
  820.             elif y is not None:
  821.                 QToolTip.add(defaultPushButton, self.__tr('Set to default value of "%1".').arg(y))
  822.  
  823.             self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked)
  824.             self.connect(optionComboBox, SIGNAL("activated(const QString&)"), self.optionComboBox_activated)
  825.             
  826.             control = optionComboBox
  827.  
  828.         elif typ == cups.UI_SPINNER: # Spinner widget
  829.             widget = self.getWidget()
  830.  
  831.             layout1 = QHBoxLayout(widget,5,10, "layout1")
  832.  
  833.             textLabel1 = QLabel(widget, "textLabel1")
  834.             layout1.addWidget(textLabel1)
  835.  
  836.             spacer1 = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
  837.             layout1.addItem(spacer1)
  838.  
  839.             optionSpinBox = OptionSpinBox(widget,"optionSpinBox", group, option, default)
  840.             layout1.addWidget(optionSpinBox)
  841.  
  842.             defaultPushButton = DefaultPushButton(widget, "defaultPushButton", group, option, choices, 
  843.                 default, optionSpinBox, typ)
  844.  
  845.             optionSpinBox.setDefaultPushbutton(defaultPushButton)
  846.  
  847.             layout1.addWidget(defaultPushButton)
  848.  
  849.             min, max = choices
  850.             optionSpinBox.setMinValue(min)
  851.             optionSpinBox.setMaxValue(max)
  852.             optionSpinBox.setValue(value)
  853.  
  854.             if suffix:
  855.                 optionSpinBox.setSuffix(suffix)
  856.  
  857.             textLabel1.setText(text)
  858.             defaultPushButton.setText("Default")
  859.  
  860.             self.connect(optionSpinBox, SIGNAL("valueChanged(int)"), self.optionSpinBox_valueChanged)
  861.             self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked)
  862.  
  863.             if value == default:
  864.                 defaultPushButton.setEnabled(False)
  865.  
  866.             if read_only:
  867.                 self.optionSpinBox.setEnabled(False)
  868.                 self.defaultPushButton.setEnabled()
  869.             else:
  870.                 QToolTip.add(defaultPushButton, 
  871.                     self.__tr('Set to default value of "%1".').arg(default))
  872.  
  873.         elif typ == cups.UI_BANNER_JOB_SHEETS:  # Job sheets widget
  874.             widget = self.getWidget()
  875.             
  876.             layout1 = QGridLayout(widget,1,1,5,10,"layout1")
  877.     
  878.             startComboBox = OptionComboBox(0, widget, "startComboBox", group, 
  879.                 "start", choices, default, typ)
  880.                 
  881.             layout1.addWidget(startComboBox,0,3)
  882.     
  883.             startTextLabel = QLabel(widget,"startTextLabel")
  884.             layout1.addWidget(startTextLabel,0,2)
  885.     
  886.             endTextLabel = QLabel(widget,"endTextLabel")
  887.             layout1.addWidget(endTextLabel,0,4)
  888.     
  889.             endComboBox = OptionComboBox(0, widget, "endComboBox", group, "end", choices, 
  890.                 default, typ, startComboBox)
  891.                 
  892.             layout1.addWidget(endComboBox,0,5)
  893.             
  894.             startComboBox.setOther(endComboBox)
  895.     
  896.             defaultPushButton = DefaultPushButton(widget, "defaultPushButton", group, option, choices, 
  897.                 default, (startComboBox, endComboBox), typ)
  898.             
  899.             layout1.addWidget(defaultPushButton,0,6)
  900.  
  901.             startComboBox.setDefaultPushbutton(defaultPushButton)
  902.             endComboBox.setDefaultPushbutton(defaultPushButton)
  903.             
  904.             textLabel1 = QLabel(widget,"textLabel1")
  905.             layout1.addWidget(textLabel1,0,0)
  906.             
  907.             spacer1 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  908.             layout1.addItem(spacer1,0,1)
  909.             
  910.             textLabel1.setText(text)
  911.             defaultPushButton.setText("Default")
  912.             
  913.             startTextLabel.setText(self.__tr("Start:"))
  914.             endTextLabel.setText(self.__tr("End:"))
  915.  
  916.             s, e, y, z = None, None, None, None
  917.             for c, t in choices:
  918.                 d = c.lower()
  919.                 if value is not None:
  920.                     if d == value[0].lower():
  921.                         s = t
  922.                     
  923.                     if d == value[1].lower():
  924.                         e = t
  925.  
  926.                 if d == default[0].lower():
  927.                     y = t
  928.                     
  929.                 if d == default[1].lower():
  930.                     z = t
  931.  
  932.                 startComboBox.insertItem(t)
  933.                 endComboBox.insertItem(t)
  934.  
  935.             if s is not None:
  936.                 startComboBox.setCurrentText(s)
  937.                 
  938.             if e is not None:
  939.                 endComboBox.setCurrentText(e)
  940.  
  941.             if value is not None and \
  942.                 value[0].lower() == default[0].lower() and \
  943.                 value[1].lower() == default[1].lower():
  944.                 
  945.                 defaultPushButton.setEnabled(False)
  946.  
  947.             if y is not None and z is not None:
  948.                 QToolTip.add(defaultPushButton, self.__tr('Set to default value of "Start: %1, End: %2".').arg(y).arg(z))
  949.  
  950.             self.connect(startComboBox, SIGNAL("activated(const QString&)"), self.optionComboBox_activated)
  951.             self.connect(endComboBox, SIGNAL("activated(const QString&)"), self.optionComboBox_activated)
  952.             self.connect(defaultPushButton, SIGNAL("clicked()"), self.defaultPushButton_clicked)
  953.             
  954.         elif typ == cups.PPD_UI_PICKMANY:
  955.             log.error("Unrecognized type: pickmany")
  956.  
  957.         elif typ == cups.UI_UNITS_SPINNER:
  958.             widget = self.getWidget()
  959.             
  960.             layout1 = QHBoxLayout(widget,5,10,"layout1")
  961.  
  962.             textLabel1 = QLabel(widget,"textLabel1")
  963.             layout1.addWidget(textLabel1)
  964.             
  965.             spacer1 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  966.             layout1.addItem(spacer1)
  967.     
  968.             lineEdit1 = QLineEdit(widget,"lineEdit1")
  969.             layout1.addWidget(lineEdit1)
  970.     
  971.             comboBox1 = QComboBox(0,widget,"comboBox1")
  972.             layout1.addWidget(comboBox1)
  973.     
  974.             defaultPushButton = QPushButton(widget,"defaultPushButton")
  975.             layout1.addWidget(defaultPushButton)
  976.             
  977.             textLabel1.setText(text)
  978.             defaultPushButton.setText("Default")
  979.             
  980.         else:
  981.             log.error("Invalid UI value: %s/%s" % (group, option))
  982.  
  983.         if widget is not None:
  984.             self.addWidget(widget, "o:"+option, control)
  985.             return widget
  986.             
  987.  
  988.  
  989.     def __tr(self,s,c = None):
  990.         return qApp.translate("ScrollPrintSettingsView",s,c)
  991.  
  992.